﻿
var gulp = require('gulp');
var concat = require('gulp-concat');
var angularFileSort = require('gulp-angular-filesort');
var strip = require('gulp-strip-line');
var templateCache = require('gulp-angular-templatecache');
var uglify = require('gulp-uglify');

gulp.task('buildMenuTemplateCache', function () {
    return gulp
        .src([
            './ext-modules/ecMenu/**/*.html'
        ])
        .pipe(templateCache({
            root: 'ext-modules/ecMenu/',
            module: 'ecMenu'
        }))
        .pipe(gulp.dest('./ext-modules/ecMenu/'));
});

gulp.task('buildDashboardTemplateCache', function () {
    return gulp
        .src([
            './ext-modules/ecDashboard/**/*.html'
        ])
        .pipe(templateCache({
            root: 'ext-modules/ecDashboard/',
            module: 'ecDashboard'
        }))
        .pipe(gulp.dest('./ext-modules/ecDashboard/'));
});

gulp.task('buildFrameworkTemplateCache', function () {
    return gulp
        .src([
            './ext-modules/ecFramework/**/*.html'
        ])
        .pipe(templateCache({
            root: 'ext-modules/ecFramework/',
            module: 'ecFramework'
        }))
        .pipe(gulp.dest('./ext-modules/ecFramework/'));
});

gulp.task('ecFramework', function () {
    return gulp
        .src([
            './ext-modules/**/*.js'
        ])
        .pipe(angularFileSort())
        .pipe(strip(["use strict"]))
        .pipe(concat('ecFramework.js'))
        .pipe(gulp.dest('./dist/'))
});

gulp.task('ecFrameworkMinfied', function () {
    return gulp
        .src([
            './ext-modules/**/*.js'
        ])
        .pipe(angularFileSort())
        .pipe(strip(["use strict"]))
        .pipe(concat('ecFramework.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist/'))
});

gulp.task('buildCSS', function () {
    return gulp
        .src([
            './ext-modules/**/*.cs'
        ])
        .pipe(concat('ecFramework.css'))
        .pipe(gulp.dest('./dist/'))
});

gulp.task('ecDistFramework', ['buildMenuTemplateCache', 'buildDashboardTemplateCache', 'buildFrameworkTemplateCache', 'ecFrameworkMinfied']);
